package cate.game.play.skill.passive.exp;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 当自身生命低于50%击杀武将时，有65%概率使自身生命值恢复到最大生命值的70%，每场战斗仅可触发1次，坦克触发恢复效果减半
 */
public class 浴血奋战PH extends PassiveHandler {

	private int 检测血量;

	private int 概率;

	private double 恢复生命;

	private byte 减半职业;

	//检测血量=5000&概率=6500&恢复生命=7000&减半职业=3
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		检测血量 = args.getInt("检测血量", 0);
		概率 = args.getInt("概率", 0);
		恢复生命 = args.getWDouble("恢复生命", 0d);
		减半职业 = args.getByte("减半职业", (byte)0);
	}

	private boolean heal;

	@Override
	public void onKill(ActionCtx action, Fighter target) {
		if (heal) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() >= 检测血量) {
			return;
		}
		if (!XT.chance(概率)) {
			return;
		}
		heal = true;
		double value = skill.owner.attr.total().hpTotal() * 恢复生命 - skill.owner.attr.total().hpCur();
		if (skill.owner.getJob() == 减半职业) {
			value /= 2;
		}
		skill.owner.attr.passiveHeal(action, value);
	}
}
